/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 31.10.2003 by RST.
// $Id: player_state_t.java,v 1.4 2004/08/20 21:29:58 salomo Exp $
using System;
//UPGRADE_TODO: The type 'java.nio.ByteBuffer' could not be found. If it was not included in the conversion, there may be compiler issues. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1262'"
using ByteBuffer = java.nio.ByteBuffer;
using Suake2.UI;
using Com = Suake2.UI.qcommon.Com;
using Lib = Suake2.UI.util.Lib;
using Math3D = Suake2.UI.util.Math3D;
namespace Suake2.UI.game
{
	
	/// <summary>Player_state_t is the information needed in addition to pmove_state_t
	/// to rendered a view.  There will only be 10 player_state_t sent each second,
	/// but the number of pmove_state_t changes will be relative to client
	/// frame rates.
	/// </summary>
	
	public class player_state_t
	{
		public player_state_t()
		{
			InitBlock();
		}
		private void  InitBlock()
		{
			stats = new short[Defines.MAX_STATS];
		}
		/// <summary>Clones the object.</summary>
		virtual public player_state_t Clone
		{
			get
			{
				return new player_state_t().set_Renamed(this);
			}
			
		}
		
		public pmove_state_t pmove = new pmove_state_t(); // for prediction
		
		// these fields do not need to be communicated bit-precise
		public float[] viewangles = new float[]{0, 0, 0}; // for fixed views
		public float[] viewoffset = new float[]{0, 0, 0}; // add to pmovestate->origin
		public float[] kick_angles = new float[]{0, 0, 0}; // add to view direction to get render angles
		
		// set by weapon kicks, pain effects, etc
		public float[] gunangles = new float[]{0, 0, 0};
		public float[] gunoffset = new float[]{0, 0, 0};
		public int gunindex;
		public int gunframe;
		
		public float[] blend = new float[4]; // rgba full screen effect
		
		public float fov; // horizontal field of view
		
		public int rdflags; // refdef flags
		
		//UPGRADE_NOTE: The initialization of  'stats' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'"
		public short[] stats;
		
		/// <summary>Lets cleverly reset the structure. </summary>
		private static player_state_t prototype = new player_state_t();
		
		/// <summary>Clears the player_state.</summary>
		public virtual void  clear()
		{
			this.set_Renamed(prototype);
		}
		
		/// <summary>Copies the player state data. </summary>
		public virtual player_state_t set_Renamed(player_state_t from)
		{
			pmove.set_Renamed(from.pmove);
			Math3D.VectorCopy(from.viewangles, viewangles);
			Math3D.VectorCopy(from.viewoffset, viewoffset);
			Math3D.VectorCopy(from.kick_angles, kick_angles);
			
			Math3D.VectorCopy(from.gunangles, gunangles);
			Math3D.VectorCopy(from.gunoffset, gunoffset);
			
			gunindex = from.gunindex;
			gunframe = from.gunframe;
			
			blend[0] = from.blend[0];
			blend[1] = from.blend[1];
			blend[2] = from.blend[2];
			blend[3] = from.blend[3];
			
			fov = from.fov;
			rdflags = from.rdflags;
			
			Array.Copy(from.stats, 0, stats, 0, Defines.MAX_STATS);
			
			return this;
		}
		
		/// <summary>Reads a player_state from a file.</summary>
		//UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
		public virtual void  load(System.IO.FileStream f)
		{
			pmove.load(f);
			
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			viewangles[0] = temp_BinaryReader.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			viewangles[1] = temp_BinaryReader2.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			viewangles[2] = temp_BinaryReader3.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			viewoffset[0] = temp_BinaryReader4.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			viewoffset[1] = temp_BinaryReader5.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader6;
			temp_BinaryReader6 = new System.IO.BinaryReader(f);
			temp_BinaryReader6.BaseStream.Position = f.Position;
			viewoffset[2] = temp_BinaryReader6.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader7;
			temp_BinaryReader7 = new System.IO.BinaryReader(f);
			temp_BinaryReader7.BaseStream.Position = f.Position;
			kick_angles[0] = temp_BinaryReader7.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader8;
			temp_BinaryReader8 = new System.IO.BinaryReader(f);
			temp_BinaryReader8.BaseStream.Position = f.Position;
			kick_angles[1] = temp_BinaryReader8.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader9;
			temp_BinaryReader9 = new System.IO.BinaryReader(f);
			temp_BinaryReader9.BaseStream.Position = f.Position;
			kick_angles[2] = temp_BinaryReader9.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader10;
			temp_BinaryReader10 = new System.IO.BinaryReader(f);
			temp_BinaryReader10.BaseStream.Position = f.Position;
			gunangles[0] = temp_BinaryReader10.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader11;
			temp_BinaryReader11 = new System.IO.BinaryReader(f);
			temp_BinaryReader11.BaseStream.Position = f.Position;
			gunangles[1] = temp_BinaryReader11.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader12;
			temp_BinaryReader12 = new System.IO.BinaryReader(f);
			temp_BinaryReader12.BaseStream.Position = f.Position;
			gunangles[2] = temp_BinaryReader12.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader13;
			temp_BinaryReader13 = new System.IO.BinaryReader(f);
			temp_BinaryReader13.BaseStream.Position = f.Position;
			gunoffset[0] = temp_BinaryReader13.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader14;
			temp_BinaryReader14 = new System.IO.BinaryReader(f);
			temp_BinaryReader14.BaseStream.Position = f.Position;
			gunoffset[1] = temp_BinaryReader14.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader15;
			temp_BinaryReader15 = new System.IO.BinaryReader(f);
			temp_BinaryReader15.BaseStream.Position = f.Position;
			gunoffset[2] = temp_BinaryReader15.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader16;
			temp_BinaryReader16 = new System.IO.BinaryReader(f);
			temp_BinaryReader16.BaseStream.Position = f.Position;
			gunindex = temp_BinaryReader16.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader17;
			temp_BinaryReader17 = new System.IO.BinaryReader(f);
			temp_BinaryReader17.BaseStream.Position = f.Position;
			gunframe = temp_BinaryReader17.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader18;
			temp_BinaryReader18 = new System.IO.BinaryReader(f);
			temp_BinaryReader18.BaseStream.Position = f.Position;
			blend[0] = temp_BinaryReader18.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader19;
			temp_BinaryReader19 = new System.IO.BinaryReader(f);
			temp_BinaryReader19.BaseStream.Position = f.Position;
			blend[1] = temp_BinaryReader19.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader20;
			temp_BinaryReader20 = new System.IO.BinaryReader(f);
			temp_BinaryReader20.BaseStream.Position = f.Position;
			blend[2] = temp_BinaryReader20.ReadSingle();
			System.IO.BinaryReader temp_BinaryReader21;
			temp_BinaryReader21 = new System.IO.BinaryReader(f);
			temp_BinaryReader21.BaseStream.Position = f.Position;
			blend[3] = temp_BinaryReader21.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader22;
			temp_BinaryReader22 = new System.IO.BinaryReader(f);
			temp_BinaryReader22.BaseStream.Position = f.Position;
			fov = temp_BinaryReader22.ReadSingle();
			
			System.IO.BinaryReader temp_BinaryReader23;
			temp_BinaryReader23 = new System.IO.BinaryReader(f);
			temp_BinaryReader23.BaseStream.Position = f.Position;
			rdflags = temp_BinaryReader23.ReadInt32();
			
			for (int n = 0; n < Defines.MAX_STATS; n++)
			{
				System.IO.BinaryReader temp_BinaryReader24;
				temp_BinaryReader24 = new System.IO.BinaryReader(f);
				temp_BinaryReader24.BaseStream.Position = f.Position;
				stats[n] = temp_BinaryReader24.ReadInt16();
			}
		}
		
		/// <summary>Writes a player_state to a file.</summary>
		//UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
		public virtual void  write(System.IO.FileStream f)
		{
			pmove.write(f);
			
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Single) viewangles[0]);
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Single) viewangles[1]);
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Single) viewangles[2]);
			
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Single) viewoffset[0]);
			System.IO.BinaryWriter temp_BinaryWriter5;
			temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter5.Write((System.Single) viewoffset[1]);
			System.IO.BinaryWriter temp_BinaryWriter6;
			temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter6.Write((System.Single) viewoffset[2]);
			
			System.IO.BinaryWriter temp_BinaryWriter7;
			temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter7.Write((System.Single) kick_angles[0]);
			System.IO.BinaryWriter temp_BinaryWriter8;
			temp_BinaryWriter8 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter8.Write((System.Single) kick_angles[1]);
			System.IO.BinaryWriter temp_BinaryWriter9;
			temp_BinaryWriter9 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter9.Write((System.Single) kick_angles[2]);
			
			System.IO.BinaryWriter temp_BinaryWriter10;
			temp_BinaryWriter10 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter10.Write((System.Single) gunangles[0]);
			System.IO.BinaryWriter temp_BinaryWriter11;
			temp_BinaryWriter11 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter11.Write((System.Single) gunangles[1]);
			System.IO.BinaryWriter temp_BinaryWriter12;
			temp_BinaryWriter12 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter12.Write((System.Single) gunangles[2]);
			
			System.IO.BinaryWriter temp_BinaryWriter13;
			temp_BinaryWriter13 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter13.Write((System.Single) gunoffset[0]);
			System.IO.BinaryWriter temp_BinaryWriter14;
			temp_BinaryWriter14 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter14.Write((System.Single) gunoffset[1]);
			System.IO.BinaryWriter temp_BinaryWriter15;
			temp_BinaryWriter15 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter15.Write((System.Single) gunoffset[2]);
			
			System.IO.BinaryWriter temp_BinaryWriter16;
			temp_BinaryWriter16 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter16.Write((System.Int32) gunindex);
			System.IO.BinaryWriter temp_BinaryWriter17;
			temp_BinaryWriter17 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter17.Write((System.Int32) gunframe);
			
			System.IO.BinaryWriter temp_BinaryWriter18;
			temp_BinaryWriter18 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter18.Write((System.Single) blend[0]);
			System.IO.BinaryWriter temp_BinaryWriter19;
			temp_BinaryWriter19 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter19.Write((System.Single) blend[1]);
			System.IO.BinaryWriter temp_BinaryWriter20;
			temp_BinaryWriter20 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter20.Write((System.Single) blend[2]);
			System.IO.BinaryWriter temp_BinaryWriter21;
			temp_BinaryWriter21 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter21.Write((System.Single) blend[3]);
			
			System.IO.BinaryWriter temp_BinaryWriter22;
			temp_BinaryWriter22 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter22.Write((System.Single) fov);
			
			System.IO.BinaryWriter temp_BinaryWriter23;
			temp_BinaryWriter23 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter23.Write((System.Int32) rdflags);
			
			for (int n = 0; n < Defines.MAX_STATS; n++)
			{
				System.IO.BinaryWriter temp_BinaryWriter24;
				temp_BinaryWriter24 = new System.IO.BinaryWriter(f);
				temp_BinaryWriter24.Write((System.Int16) stats[n]);
			}
		}
		
		/// <summary>Prints the player state. </summary>
		public virtual void  dump()
		{
			pmove.dump();
			
			Lib.printv("viewangles", viewangles);
			Lib.printv("viewoffset", viewoffset);
			Lib.printv("kick_angles", kick_angles);
			Lib.printv("gunangles", gunangles);
			Lib.printv("gunoffset", gunoffset);
			
			Com.Println("gunindex: " + gunindex);
			Com.Println("gunframe: " + gunframe);
			
			Lib.printv("blend", blend);
			
			Com.Println("fov: " + fov);
			
			Com.Println("rdflags: " + rdflags);
			
			for (int n = 0; n < Defines.MAX_STATS; n++)
				System.Console.Out.WriteLine("stats[" + n + "]: " + stats[n]);
		}
	}
}